package com.eight.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eight.mapper.ChatMapper;
import com.eight.pojo.ChatData;
import com.eight.service.ChatService;
import com.eight.vo.ComResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description: 聊天业务的业务层
 * @Author: Van.Planifolia
 * @CreateTime: 2023-03-02  20:05
 * @Version: 1.0
 */
@Service("chatService")
public class ChatServiceImpl extends ServiceImpl<ChatMapper, ChatData> implements ChatService {
    @Autowired
    private ChatMapper chatMapper;

    /**
     * 查询俩个人的聊天记录
     *
     * @param from 来自
     * @param to   发送给
     * @return 结果
     */
    @Override
    public ComResult searchRecords(String from, String to) {
        QueryWrapper<ChatData> query = new QueryWrapper<>();
        query.eq("froms", from).eq("tos", to)
                .or()
                .eq("tos", from).eq("froms", to)
                .orderByAsc("sendtime");
        return new ComResult(2000, "查询成功", chatMapper.selectList(query));
    }
}
